#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int INF = 2e9 + 5;
struct node
{
    int x, y,cost, type;
    node(){}
    node(int xx, int yy, int cc, int tt): x(xx), y(yy), cost(cc), type(tt){}
};
int cmp(node a, node b)
{
    if(a.x == b.x)
        return a.type < b.type;
    return a.x < b.x;
}
vector<node> v;
int sum[maxn];
int main()
{
    int n, x;
    while(~scanf("%d%d", &n, &x))
    {
        int l, r, c;
        v.clear();
        memset(sum, 0, sizeof(sum));
        for(int i = 1; i <= n; i++)
        {
            scanf("%d%d%d", &l, &r, &c);
            v.push_back(node(l, r, c, -1));
            v.push_back(node(r, l, c, 1));
        }
        sort(v.begin(), v.end(), cmp);
        int ans = INF;
        for(int i = 0; i < v.size(); i++)
        {
            if(v[i].type == -1)
            {
                int temp = v[i].y-v[i].x+1;
                if(temp >= x || !sum[x-temp]) continue;
                ans = min(ans, sum[x-temp]+v[i].cost);
            }
            else
            {
                int temp = v[i].x-v[i].y+1;
                if(!sum[temp] || sum[temp] > v[i].cost)
                    sum[temp] = v[i].cost;
            }
        }
        if(ans != INF)
            printf("%d\n", ans);
        else
            printf("-1\n");
    }
    return 0;
}

